<script setup lang="ts">

import {getCurrentInstance, ref} from "vue";
import Blog_table, {type optionType} from "@/components/admin/blog_table.vue";
import {menuDelAxios} from "@/api/menu_api";
import {Message} from "@arco-design/web-vue";
import {advertListAxios, type AdvertListRsp} from "@/api/promotion_api";
import Promotion_add_modal from "@/views/admin/system/promotion_add_modal.vue";
import Promotion_update_modal from "@/views/admin/system/promotion_update_modal.vue";

const columns = [
  {title: '标题', dataIndex: 'title',},
  {title: '图片', slotName: 'image',},
  {title: '链接', slotName: 'href',},
  {title: '是否显示', slotName: 'is_show',},
  {title: '更新时间', slotName: 'updated_at',},
  {title: '操作', slotName: 'action',},
]
const actionOptionList = ref<optionType[]>([
  {label: "批量删除", value: 1},
])

const mitt = getCurrentInstance()

const check = true

mitt?.proxy?.$Bus.on("del", (id_list) => {
  del(id_list as number[])
  mitt?.proxy?.$Bus.emit("refresh")
})

async function del(id_list: number[]) {
  let rsp = await menuDelAxios({id_list: id_list})
  if (rsp.code === 0) {
    Message.success(rsp.msg)
    mitt?.proxy?.$Bus.emit("refresh")
    return
  }
  Message.success(rsp.msg)
}

</script>

<template>
  <div class="menu_list_view">
    <promotion_add_modal></promotion_add_modal>

    <promotion_update_modal></promotion_update_modal>

    <blog_table :url="advertListAxios"
                :optionTypeList="actionOptionList"
                :check="check"
                :columns="columns"
                :limit="10"
                add="添加广告"
                update="编辑"
                del="删除">

      <template #image="{record}:{record:AdvertListRsp}">
        <a-image
            height="80px"
            style="border-radius: 5px"
            :src="record.image"
        >
        </a-image>
      </template>

      <template #href="{record}:{record:AdvertListRsp}">
        <a-link :href="record.href">
          {{ record.href }}
        </a-link>
      </template>

      <template #is_show="{record}:{record:AdvertListRsp}">
        <a-tag v-if="record.is_show" color="arcoblue">
          显示
        </a-tag>
        <a-tag v-else>
          不显示
        </a-tag>
      </template>
    </blog_table>
  </div>
</template>

<style lang="scss">

</style>
